package net.hanjava.test;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;

import net.hanjava.widget.AbstractNotifier;

public class ThinkFreeNotifier extends AbstractNotifier {
	private ImageIcon icon = null;
	private Dimension size = null;

	public ThinkFreeNotifier() {
		try {
			URL imgUrl = new URL("http://dev.thinkfree.com/forum/files/fm_notice_175_120_154.png");
			icon = new ImageIcon(imgUrl);
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
	}

	@Override
	protected Animation createAnimation() {
		// use default animation
		return null;
	}

	@Override
	protected JComponent createSlidingComponent() {
		JLabel label = new JLabel( icon );
		return label;
	}

	@Override
	protected Dimension getRequiredSize() {
		if(size==null) {
			size = new Dimension( icon.getIconWidth(), icon.getIconHeight() );
		}
		return size;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		JFrame frame = new JFrame("Test Button");
		frame.setAlwaysOnTop(true);
		final AbstractNotifier notifier = new ThinkFreeNotifier();
		AbstractAction actionNotify = new AbstractAction("Notify") {
			public void actionPerformed(ActionEvent e) {
				notifier.doNotify();
			}
		};
		frame.add(new JButton(actionNotify));
		frame.setSize(100, 100);
		frame.setVisible(true);
	}
}